/**
 * 
 */
package com.jie.eclipse.pan.editors.form;

import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;

import com.jie.eclipse.pan.bind.PageDataBind;
import com.jie.eclipse.pan.dao.QMDao;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.editors.utils.PanImageHelper;
import com.jie.eclipse.pan.gef.dialog.BaseDialog;
import com.jie.eclipse.pan.gef.dialog.LogDialog;
import com.jie.eclipse.pan.gef.dialog.OwnerDialog;
import com.jie.eclipse.pan.swtitem.ListGroup;
import com.jie.eclipse.pan.swtitem.actiongroup.LogPageActionGroup;
import com.jie.eclipse.pan.swtitem.table.PTable;
import com.jie.eclipse.pan.swtitem.table.PTableColumn;
import com.jie.eclipse.pan.swtitem.table.PTableViewer;
import com.jie.eclipse.pan.swtitem.table.PllTableContentProvider;
import com.jie.eclipse.pan.swtitem.table.PllTableLabelProvider;
import com.jie.eclipse.pan.swtitem.table.sort.LogSorter;
import com.jie.eclipse.pan.utils.StringBuilderEx;
import com.jie.eclipse.pan.utils.StringHelper;

/**
 * @author yanjie
 *
 */
public class LogPage extends BasePage {
	private FormToolkit toolkit = null;
	private Color bgcolor = null;
	private PageDataBind bind = null;
	private PTableViewer tv1 = null;
	public static final String ID = "com.jie.eclipse.pan.editors.page.logpage";
	private Menu tableMenu = null;
	
	public LogPage(FormEditor editor) {
		super(editor, ID, "系統日志");
	}
	
	@Override
	protected void createFormContent(IManagedForm managedForm) {
		bind = new PageDataBind();
		bgcolor = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
		ScrolledForm form = managedForm.getForm();
		toolkit = managedForm.getToolkit();
		Composite body = managedForm.getForm().getBody();
		body.setLayout(new GridLayout(1, false));
		body.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		ViewForm vform= new ViewForm(body, SWT.NONE);
		vform.setBackground(bgcolor);
		vform.setLayout(new GridLayout());
		GridData vformData = new GridData(GridData.FILL_BOTH);
		vformData.heightHint = 150;
		vform.setLayoutData(vformData);
		
		ToolBar toolbar1 = new ToolBar(vform, SWT.FLAT | SWT.RIGHT );
		toolbar1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		toolbar1.setBackground(bgcolor);
		ToolBarManager toolbarMgr = new ToolBarManager(toolbar1);
		
		LogPageActionGroup logAction = new LogPageActionGroup(this);
		logAction.fillContextMenu(new MenuManager());
		logAction.fillActionToolbars(toolbarMgr);
		
		Composite parent = new Composite(vform, SWT.NONE);
		//设置表单的布局
		parent.setBackground(bgcolor);
		parent.setLayout(new GridLayout(1, false));
		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		creatSearchComposite(parent);
		creatGridComposite(parent);
		
		vform.setTopLeft(toolbar1);
		vform.setContent(parent);
	}
	
	private void creatSearchComposite(Composite parent){
		Group group1 = new Group(parent, SWT.NULL);
		group1.setText("查詢條件");
		group1.setLayout(new GridLayout(8, false));
		group1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		
		Label lab1 = toolkit.createLabel(group1, "页面路径:", SWT.RIGHT);
		lab1.setBackground(bgcolor);
		
		Text pagePath = toolkit.createText(group1, "",SWT.BORDER);
		pagePath.setLayoutData(new GridData(120, 15));
		bind.bind("pagePath", pagePath);
		
		Label lab2 = toolkit.createLabel(group1, "負責人:", SWT.RIGHT);
		lab2.setBackground(bgcolor);
		
		Combo owner = new Combo(group1, SWT.READ_ONLY);
		String[][] fzrs = QMDao.getInstance().getPanLogFZR(true,true);
		owner.setItems(fzrs[0]);
		owner.select(0);
		owner.setLayoutData(new GridData(100, 24));
		for (int i = 0; i < fzrs[1].length; i++) {
			owner.setData(String.valueOf(i), fzrs[1][i]);
		}
		bind.bind("owner", owner);
		
		Label lab3 = toolkit.createLabel(group1, "日期:", SWT.RIGHT);
		lab3.setBackground(bgcolor);
		
		Date curDate = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.MONTH, -1);
		
		DateTime day1 = new DateTime(group1, SWT.NONE);
		day1.setLayoutData(new GridData(80, 15));
		day1.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
		bind.bind("day1", day1);
		
		Label lab4 = toolkit.createLabel(group1, "~", SWT.RIGHT);
		lab4.setBackground(bgcolor);
		 
		DateTime day2 = new DateTime(group1, SWT.NONE);
		day2.setLayoutData(new GridData(80, 15));
		bind.bind("day2", day2);
		
		Label lb6 =toolkit.createLabel(group1, "Top:");
		lb6.setBackground(bgcolor);
		
		Combo top = new Combo(group1, SWT.READ_ONLY);
		top.setItems(new String[]{"100","200","300","400","500","1000","2000"});
		top.select(0);
		top.setLayoutData(new GridData(100, 24));
		top.setData("0","100");
		top.setData("1","200");
		top.setData("2","300");
		top.setData("3","400");
		top.setData("4","500");
		top.setData("5","1000");
		top.setData("6","2000");
		bind.bind("top", top);
		
		Label lb7 =toolkit.createLabel(group1, "日志(%):");
		lb7.setBackground(bgcolor);
		
		Text msg = toolkit.createText(group1, "",SWT.BORDER);
		msg.setLayoutData(new GridData(120, 15));
		bind.bind("msg", msg);
		
		Label lb5 =toolkit.createLabel(group1, "状态:");
		lb5.setBackground(bgcolor);
		ListGroup status = new ListGroup(group1, "radio");
		GridData gd = new GridData();
		gd.horizontalSpan = 3;
		status.setLayoutData(gd);
		status.setLayout(new GridLayout(3, false));
		status.setData("xtype", "ridio");
		Button btn1 = status.getNewButton();
		btn1.setData("0");
		btn1.setText("未处理");
		Button btn2= status.getNewButton();
		btn2.setData("1");
		btn2.setText("已处理");
		Button btn3= status.getNewButton();
		btn3.setData("");
		btn3.setText("ALL");
		btn3.setSelection(true);
		bind.bind("status_code", status);
	}
	
	private void creatGridComposite(Composite parent){
		tv1 = new PTableViewer(new PTable(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION));
		
		PTable table = tv1.getPTable();
		table.setLayout(new GridLayout());
		GridData tableGridData = new GridData(GridData.FILL_BOTH);
		table.setLayoutData(tableGridData);
		table.setHeaderVisible(true); // 表头显示
		table.setLinesVisible(true); // 表格线显示
		
		TableLayout tLayout = new TableLayout();
		table.setLayout(tLayout);
		
		tLayout.addColumnData(new ColumnWeightData(5));
		PTableColumn col1 = new PTableColumn(table, SWT.NONE);
		col1.setText("ID");
		col1.setName("sn");
		col1.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.SN_ASC:LogSorter.SN_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(8));
		PTableColumn col3 = new PTableColumn(table, SWT.NONE);
		col3.setText("负责人");
		col3.setName("owner");
		col3.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.OWNER_ASC:LogSorter.OWNER_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(15));
		PTableColumn col4 = new PTableColumn(table, SWT.NONE);
		col4.setText("页面名称");
		col4.setName("pageName");
		col4.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.PAGENAME_ASC:LogSorter.PAGENAME_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(30));
		PTableColumn col9 = new PTableColumn(table, SWT.NONE);
		col9.setText("日志摘要");
		col9.setName("errmsg");
		col9.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.ERRMSG_ASC:LogSorter.ERRMSG_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(8));
		PTableColumn col6 = new PTableColumn(table, SWT.NONE);
		col6.setText("状态");
		col6.setName("status");
		col6.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.STATUS_ASC:LogSorter.STATUS_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(20));
		PTableColumn col5 = new PTableColumn(table, SWT.NONE);
		col5.setText("页面路径");
		col5.setName("pagePath");
		col5.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.PAGEPATH_ASC:LogSorter.PAGEPATH_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(15));
		PTableColumn col7 = new PTableColumn(table, SWT.NONE);
		col7.setText("日誌創建時間");
		col7.setName("crtday");
		col7.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.CRTDAY_ASC:LogSorter.CRTDAY_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(15));
		PTableColumn col8 = new PTableColumn(table, SWT.NONE);
		col8.setText("日誌修改時間");
		col8.setName("updday");
		col8.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.UPDDAY_ASC:LogSorter.UPDDAY_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(10));
		PTableColumn col2 = new PTableColumn(table, SWT.NONE);
		col2.setText("主机");
		col2.setName("hostip");
		col2.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.HOSTIP_ASC:LogSorter.HOSTIP_DESC);
                asc = !asc;
            }
        });
		
		tLayout.addColumnData(new ColumnWeightData(5));
		PTableColumn col13 = new PTableColumn(table, SWT.NONE);
		col13.setText("使用者");
		col13.setName("crtname");
		
		col13.addSelectionListener(new SelectionAdapter(){
            boolean asc = true;
            public void widgetSelected(SelectionEvent e){
                tv1.setSorter(asc?LogSorter.CRTNAME_ASC:LogSorter.CRTNAME_DESC);
                asc = !asc;
            }
        });
		
		//創建表格的右鍵菜單
		createTableMenu(parent);
		table.setMenu(tableMenu);
		table.reloadColumns();
		
		//设置选中行的背景
//		final Color blue = table.getDisplay().getSystemColor(SWT.COLOR_CYAN);
//	    final Color yellow = table.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
//		table.addListener(SWT.EraseItem, new Listener() {
//			public void handleEvent(Event event) {
//				event.detail &= ~SWT.HOT;
//				if ((event.detail & SWT.SELECTED) == 0)return; /* item not selected */
//				int clientWidth = tv1.getTable().getClientArea().width;
//				GC gc = event.gc;
//				//Color oldBackground = gc.getBackground();
//				gc.setBackground(blue);
//				gc.fillRectangle(0, event.y, clientWidth, event.height);
//				//gc.setBackground(oldBackground);
//				event.detail &= ~SWT.SELECTED;
//			}
//		});
		
		tv1.setContentProvider(new PllTableContentProvider()); // 内容器
		tv1.setLabelProvider(new PllTableLabelProvider(tv1));// 标签器
		
		tv1.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(DoubleClickEvent event) {
				StructuredSelection selection = (StructuredSelection)event.getSelection();
				if(selection.getFirstElement() instanceof BaseDataEntity){
					BaseDataEntity row = (BaseDataEntity)selection.getFirstElement();
					editLOg(row);
				}
			}
		});
		
		reloadResult(true);
	}
	
	public void createTableMenu(Composite parent){
		tableMenu = new Menu(parent);
		MenuItem editItem = new MenuItem(tableMenu, SWT.PUSH);
		editItem.setText("编辑");
		editItem.setImage(PanImageHelper.getInstance().getImage("icons/icon_rowedit2.gif"));
		editItem.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				if(tv1.getSelection() instanceof StructuredSelection){
					StructuredSelection selection = (StructuredSelection)tv1.getSelection();
					editLOg((BaseDataEntity)selection.getFirstElement());
				}
			}
		});
		
		MenuItem deleteItem = new MenuItem(tableMenu, SWT.PUSH);
		deleteItem.setText("刪除");
		deleteItem.setImage(PanImageHelper.getInstance().getImage("icons/icon_delete_s.gif"));
		deleteItem.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				if(tv1.getSelection() instanceof StructuredSelection){
					if(!"yanjie".equals(QMDao.getInstance().getCurUserName())){
						MessageDialog.openWarning(tv1.getTable().getShell(), "权限警告", "您沒有权限删除log!");
						return;
					}
					deleteLog();
				}
			}
		});
		
		MenuItem reasignItem = new MenuItem(tableMenu, SWT.PUSH);
		reasignItem.setText("重新指定负责人");
		reasignItem.setImage(PanImageHelper.getInstance().getImage("icons/icon_assist_s.gif"));
		reasignItem.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				if(tv1.getSelection() instanceof StructuredSelection){
					OwnerDialog dialog = new OwnerDialog(getEditorSite().getShell(),"选择负责人对话框","负责人","请选择要指定的负责人!","负责人:");
					if (dialog != null && dialog.open() == BaseDialog.OK) {
						reAsignTo(dialog.getFzr());
					}
				}
			}
		});
		
		MenuItem reasign2Item = new MenuItem(tableMenu, SWT.PUSH);
		reasign2Item.setText("转交给其它人处理");
		reasign2Item.setImage(PanImageHelper.getInstance().getImage("icons/icon_assist_s.gif"));
		reasign2Item.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				if(tv1.getSelection() instanceof StructuredSelection){
					OwnerDialog dialog = new OwnerDialog(getEditorSite().getShell(),"选择人員对话框","人员","请选择要转交的人员!","人员:");
					if (dialog != null && dialog.open() == BaseDialog.OK) {
						reAsignTo2(dialog.getFzr());
					}
				}
			}
		});
		
		MenuItem okItem = new MenuItem(tableMenu, SWT.PUSH);
		okItem.setText("标记OK");
		okItem.setImage(PanImageHelper.getInstance().getImage("icons/icon_rowsave_s.gif"));
		okItem.addListener(SWT.Selection,new Listener() {
			public void handleEvent(Event event) {
				markStatus("1");
			}
		});
		
		MenuItem returnItem = new MenuItem(tableMenu, SWT.PUSH);
		returnItem.setText("取消标记OK");
		returnItem.setImage(PanImageHelper.getInstance().getImage("icons/icon_gotolink_s.gif"));
		returnItem.addListener(SWT.Selection,new Listener() {
			public void handleEvent(Event event) {
				markStatus("0");
			}
		});
	}
	
	public void reloadResult(boolean bdefault){
		QMDao qmDao = QMDao.getInstance();
		tv1.setInput(qmDao.getPageLogRecords(bind.getRecord(),bdefault));
	}
	
	/**
	 * @param row
	 * 編輯日誌信息
	 */
	public void editLOg(BaseDataEntity row){
		LogDialog dialog = new LogDialog(getEditorSite().getShell(), row);
		if (dialog != null && dialog.open() == BaseDialog.OK) {  
			BaseDataEntity ret = dialog.getRet();
			if(!ret.isNullOrEmpty("reasignto") || !row.gpsv("status_code").equals(ret.gpsv("status_code"))){
				PTable table = tv1.getPTable();
				TableItem item = table.getSelection()[0];
				
				//更新日志状态和负责人
				StringBuilderEx sql = new StringBuilderEx("exec pan..savelog ");
				sql.Append("%1$s",row.gpiv("pagesn"));
				sql.Append(",%1$s",row.gpiv("sn"));
				sql.Append(",'%1$s'",ret.gpsv("status_code"));
				sql.Append(",'%1$s'",ret.gpsv("reasignto"));
				sql.Append(",'%1$s'",QMDao.getIp());
				sql.Append(",'%1$s'",QMDao.getInstance().getCurUserName());
				int retCode = QMDao.getInstance().executeUpdate(QMDao.getInstance().getPanDataSource(), sql.toString());
				if(retCode >0 ){
					//更新表格
					row.spsv("status", "0".equals(ret.gpsv("status_code")) ? "未处理" : "已处理");
					if(!ret.isNullOrEmpty("reasignto"))row.spsv("owner", ret.gpsv("reasignto"));
					
					table.ReloadTableItemRecord(item, row);
					
					reloadResult(false);
				}
			}
        }
	}
	
	/**
	 * @param status
	 * 標記狀態
	 */
	public void markStatus(String status){
		if(tv1.getSelection() instanceof StructuredSelection){
			StructuredSelection selection = (StructuredSelection)tv1.getSelection();
			Iterator it = selection.iterator();
			StringBuffer sns = new StringBuffer();
			boolean bfirst = true;
			while(it.hasNext()){
				BaseDataEntity row = (BaseDataEntity)it.next();
				if(!status.equals(row.gpsv("status_code"))){
					if(!bfirst)sns.append(",");
					sns.append(row.gpsv("sn"));
					bfirst = false;
				}
			}
			if(!bfirst){
				StringBuilderEx sql = new StringBuilderEx("update pan..pan_log set ");
				sql.Append(" status = '%1$s' ",status);
				sql.Append(",updday = getdate()");
				sql.Append(",updip = '%1$s'",QMDao.getIp());
				sql.Append(",updname = '%1$s'",QMDao.getInstance().getCurLogUserName());
				sql.Append(" where sn in (%1$s)",sns.toString());
				QMDao.getInstance().executeUpdate(QMDao.getInstance().getPanDataSource(), sql.toString());
				reloadResult(false);
			}
		}
	}
	
	/**
	 * @param owner
	 * 重新指定負責人
	 */
	public void reAsignTo(String owner){
		if(StringHelper.IsNullOrEmpty(owner))return;
		StructuredSelection selection = (StructuredSelection)tv1.getSelection();
		Iterator it = selection.iterator();
		StringBuffer sns = new StringBuffer();
		boolean bfirst1 = true;
		
		StringBuffer pagesns = new StringBuffer();
		boolean bfirst2 = true;
		
		while(it.hasNext()){
			BaseDataEntity row = (BaseDataEntity)it.next();
			if(!owner.equals(row.gpsv("owner"))){
				if(row.gpiv("pagesn") > 0){
					if(!bfirst2)pagesns.append(",");
					pagesns.append(row.gpsv("pagesn"));
					bfirst2 = false;
				}else{
					if(!bfirst1)sns.append(",");
					sns.append(row.gpsv("sn"));
					bfirst1 = false;
				}
			}
		}
		
		if(!bfirst1 || !bfirst2){
			StringBuilderEx sql = new StringBuilderEx();
			if(!bfirst1){
				sql.Append(" update pan..pan_log set ");
				sql.Append(" owner = '%1$s' ",owner);
				sql.Append(",updday = getdate()");
				sql.Append(",updip = '%1$s'",QMDao.getIp());
				sql.Append(",updname = '%1$s'",QMDao.getInstance().getCurLogUserName());
				sql.Append(" where sn in (%1$s)",sns.toString());
			}
			
			if(!bfirst2){
				sql.Append("\r\n update pan..pan_page set ");
				sql.Append(" agent = '%1$s' ",owner);
				sql.Append(",updday = getdate()");
				sql.Append(",updip = '%1$s'",QMDao.getIp());
				sql.Append(",updname = '%1$s'",QMDao.getInstance().getCurLogUserName());
				sql.Append(" where sn in (%1$s)",pagesns.toString());
			}
			
			QMDao.getInstance().executeUpdate(QMDao.getInstance().getPanDataSource(), sql.toString());
			reloadResult(false);
		}
	}
	
	/**
	 * @param owner
	 * 重新指定負責人
	 */
	public void reAsignTo2(String owner){
		if(StringHelper.IsNullOrEmpty(owner))return;
		StructuredSelection selection = (StructuredSelection)tv1.getSelection();
		Iterator it = selection.iterator();
		StringBuffer sns = new StringBuffer();
		boolean bfirst1 = true;
		
		while(it.hasNext()){
			BaseDataEntity row = (BaseDataEntity)it.next();
			if(!owner.equals(row.gpsv("owner"))){
				if(!bfirst1)sns.append(",");
				sns.append(row.gpsv("sn"));
				bfirst1 = false;
			}
		}
		
		if(!bfirst1){
			StringBuilderEx sql = new StringBuilderEx();
			sql.Append(" update pan..pan_log set ");
			sql.Append(" owner = '%1$s' ",owner);
			sql.Append(",updday = getdate()");
			sql.Append(",updip = '%1$s'",QMDao.getIp());
			sql.Append(",updname = '%1$s'",QMDao.getInstance().getCurLogUserName());
			sql.Append(" where sn in (%1$s)",sns.toString());
			
			QMDao.getInstance().executeUpdate(QMDao.getInstance().getPanDataSource(), sql.toString());
			reloadResult(false);
		}
	}
	
	public void deleteLog(){
		if(tv1.getSelection() instanceof StructuredSelection){
			StructuredSelection selection = (StructuredSelection)tv1.getSelection();
			Iterator it = selection.iterator();
			StringBuffer sns = new StringBuffer();
			boolean bfirst = true;
			while(it.hasNext()){
				BaseDataEntity row = (BaseDataEntity)it.next();
				if(!bfirst)sns.append(",");
				sns.append(row.gpsv("sn"));
				bfirst = false;
			}
			if(!bfirst){
				StringBuilderEx sql = new StringBuilderEx("update pan..pan_log set ");
				sql.Append(" enab = 0 ");
				sql.Append(",updday = getdate()");
				sql.Append(",updip = '%1$s'",QMDao.getIp());
				sql.Append(",updname = '%1$s'",QMDao.getInstance().getCurLogUserName());
				sql.Append(" where sn in (%1$s)",sns.toString());
				QMDao.getInstance().executeUpdate(QMDao.getInstance().getPanDataSource(), sql.toString());
				reloadResult(false);
			}
		}
	}
}
